package com.attilax.facedetection;

import java.io.File;
import java.util.Map;
import java.util.function.Function;

import javax.management.RuntimeErrorException;

import org.apache.commons.io.FileUtils;
import org.opencv.core.Core;
import org.opencv.core.CvException;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

import com.alibaba.fastjson.JSON;
import com.attilax.img.util.OpencvUtil;
import com.attilax.io.FileExistEx;
import com.attilax.io.FileUtil;
import com.attilax.io.PathUtil;
import com.attilax.io.dirx;
import com.attilax.io.filex;
import com.attilax.io.filexEx;
import com.attilax.io.pathx;
 
import com.attilax.util.Mapx;
 
import com.attilax.util.mapUtil;
import com.attilax.util.timestampUtil;
import com.google.common.collect.Maps;

/**
 * v2 org code s323
 * 
 * @author attilax
 *
 */
@SuppressWarnings("all")
public class pickupFemBeatyPic {
	public static int num = 0;

	/**
	 * System.load( "C:\\progrm\\opencv\\build\\java\\x64\\opencv_java2413.dll"
	 * ); // System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //
	 * "C:\\progrm\\opencv\\sources\\data\\haarcascades_GPU\\haarcascade_frontalface_alt.xml";
	 * //FaceDetector.class.getResource("haarcascade_frontalface_alt.xml").
	 * getPath(); //meitu syosyo zosh use jeig d .. zaidren d blog shwa yao use
	 * haarcascades hamyar d ..
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
	 
     Logger logr=new Logger("c:\\000pickupFemBeatyPicLogdir","logpre"+timestampUtil.gettimeStamp_millsec_filenameEncode());
 //、	、、	System.out.println("\nRunning FaceDetector");
     
// 	String dir = "D:\\000atibek\\l6 foto ppl va s57";
// 	String targetDir = "d:\\000fcrzt_beaty_soreGrtthan60";
// 	String type="move";
	// 	get60Scorebeauty(logr,dir,targetDir,type);
 	
     
//  	String dir = "D:\\000atibek\\l6 foto ppl va s57";
//  	String targetDir = "d:\\000fcrzt_beaty_soreGrtthan60";
  	
   
 	String dir = "  D:\\000fcrzt_beaty_soreGrtthan60";
		String dir_picScoreJsonDir ="D:\\000atibek\\l6 foto ppl va s57";
		String  targetDir= "d:\\000fcrzt_beaty_soreGrtthan80";
		String type="move";
	 get80Scorebeauty(logr,dir,targetDir,dir_picScoreJsonDir);
		// tsetSingle();
	}
	
	
	public static void get80Scorebeauty(Logger logr, String dir2, String targetDir, String dir_picScoreJsonDir) {
		//D:\000atibek\l6 foto ppl va s57
	String	dir=dir2.trim();
	 if( !new File(dir).exists())
		 throw new RuntimeException(" dir not exist:"+dir);
		dirx.traveV3(dir, new Function<String, Object>() {

			@Override
			public Object apply(String f) {
				num++;
				System.out.println("num:" + num);

				if (f.contains("faced4dbg"))
					return null;
				if (f.endsWith(".txt"))
					return null;
				System.out.println(f);
				String rltPath = PathUtil.getRltPath( filex.getFileName_fullpathname_noExtName(f),dir);
				String picjson=dir_picScoreJsonDir+"\\"+rltPath+".txt";
		 
				logr.info(picjson);
				try {
				
					boolean beaty = jsonuti4fc.isBeaty (picjson,80);
					Mapx m = Mapx.newx().put("f", picjson).put("beaty", beaty);
 
					logr.info(JSON.toJSONString(m.mp, true));
					if( 	beaty )
					{
					 	
						FileUtil.move(f, targetDir, dir);
					}
						
 
					return null;
			 

				} catch (Exception e) {
					logr.error(JSON.toJSONString(e, true));
				}
				return f;

			}
		});
	}

	
	
	public static void getUgly(Logger logr, String dir2, String targetDir, String dir_picScoreJsonDir,	int maxScore) {
		//D:\000atibek\l6 foto ppl va s57
	String	dir=dir2.trim();
	 if( !new File(dir).exists())
		 throw new RuntimeException(" dir not exist:"+dir);
		dirx.traveV3(dir, new Function<String, Object>() {

			@Override
			public Object apply(String f) {
				num++;
				System.out.println("num:" + num);

				if (f.contains("faced4dbg"))
					return null;
				if (f.endsWith(".txt"))
					return null;
				System.out.println(f);
				String rltPath = PathUtil.getRltPath( filex.getFileName_fullpathname_noExtName(f),dir);
				String picjson=dir_picScoreJsonDir+"\\"+rltPath+".txt";
		 
				logr.info(picjson);
				try {
		 
					boolean beaty = jsonuti4fc.isUgly( picjson,maxScore);
					Mapx m = Mapx.newx().put("f", picjson).put("beaty", beaty);
 
					logr.info(JSON.toJSONString(m.mp, true));
					if( 	beaty )
					{
					 	
						FileUtil.move(f, targetDir, dir);
					}
						
 
					return null;
			 

				} catch (Exception e) {
					logr.error(JSON.toJSONString(e, true));
				}
				return f;

			}
		});
	}

	public static void get60Scorebeauty(Logger logr, String dir, String targetDir, String type) {
	
		dirx.traveV3(dir, new Function<String, Object>() {

			@Override
			public Object apply(String f) {
				num++;
				System.out.println("num:" + num);

				if (f.contains("faced4dbg"))
					return null;
				if (f.endsWith(".txt"))
					return null;
				System.out.println(f);
				String picjson=filex.getFileName_fullpathname_noExtName(f)+".txt";
		 
				logr.info(picjson);
				try {
				
					boolean beaty = jsonuti4fc.isBeaty(picjson);
					Mapx m = Mapx.newx().put("f", picjson).put("beaty", beaty);
 
					logr.info(JSON.toJSONString(m.mp, true));
					if( 	beaty )
					{
					
						FileUtil.move(f, targetDir, dir);
					}
						
//					Mapx m = Mapx.newx().put("f", f).put("fcnum", faceDetectionsRzt_MatOfRect.toArray().length);
//
//					System.out.println(JSON.toJSONString(m.mp, true));
					return null;
			 

				} catch (Exception e) {
					logr.error(JSON.toJSONString(e, true));
				}
				return f;

			}
		});
	}

 
 

 

 
}